# -*- coding: utf-8 -*-
import scrapy
from Spider.items import SpiderItem 
class ZhipinSpider(scrapy.Spider):
    name = 'zhipin'
    allowed_domains = ['zhipin.com']
    #start_urls = ['https://www.zhipin.com/c101020100-p100901/?page=1&ka=page-1']
    #我的理解
    #请求方法
    def start_requests(self):
          for value in range(1,2):
             yield scrapy.Request('https://www.zhipin.com/c101020100-p100901/?page='+str(value)+'&ka=page-'+str(value), callback=self.parse) 
    #解析方法
    def parse(self, response):
        #先判断页面是否报错再执行
        for each in  response.xpath("//html/body/div/div[3]/div/div[2]/ul/li"):
            item = SpiderItem()
            work = each.xpath("div/div[1]/div[1]/div/div[1]/span[1]/a/text()").extract()
            pos = each.xpath("div/div[1]/div[1]/div/div[1]/span[2]/span/text()").extract()
            com = each.xpath("div/div[1]/div[2]/div/h3/a/text()").extract()
            salary = each.xpath("div/div[1]/div[1]/div/div[2]/span/text()").extract()
            edu=each.xpath("div/div[1]/div[1]/div/div[2]/p/text()").extract()
            src=each.xpath("div/div[1]/div[2]/a/img/@src").extract()
            item['work']=work[0];
            item['pos']=pos[0];
            item['com']=com[0];
            item['salary']=salary[0];
            item['edu']=edu[0];
            item['src']=src[0];
            yield item;

 